package cg.studio.algorithm.test;

import java.util.Comparator;

import org.junit.Test;

import cg.studio.algorithm.search.SearchOnSorted;
import cg.studio.algorithm.search.Searcher;

public class SearchTester
{
  @Test
  public void testSearchOnSorted()
  {
    Searcher searcher = new SearchOnSorted();
    Comparator<Integer> comparator = new Comparator<Integer>()
    {
      public int compare( Integer value1, Integer value2 )
      {
        return value1.compareTo( value2 );
      }
    };
    
    {
      Integer[] array = new Integer[]{1};
      System.out.println( "has 1: " + searcher.hasValue( array, 1, comparator ) );
      System.out.println( "has 3: " + searcher.hasValue( array, 3, comparator ) );
    }
    {
      Integer[] array = new Integer[]{1, 5, 7, 10, 15, 20};
      System.out.println( "has 1: " + searcher.hasValue( array, 1, comparator ) );
      System.out.println( "has 20: " + searcher.hasValue( array, 20, comparator ) );
      System.out.println( "has 9: " + searcher.hasValue( array, 9, comparator ) );
      System.out.println( "has 10: " + searcher.hasValue( array, 10, comparator ) );
    }

  }
}
